﻿//------------------------------------------------------------------------------
// <pcdd-entitiy>
//     代理业务类库
//     月结算业务对象
// </pcdd-entitiy>
//------------------------------------------------------------------------------

using System.Collections.Generic;
using System.Text;
using CL.Business.DAL;
using CL.Enum.Common;
using CL.View.Entity.Business;
using CL.Business.Entity;
using Dapper;

namespace CL.Business.BLL
{
    /// <summary>
    /// SettleMonthBLL 业务
    /// </summary>
    public class SettleMonthBLL
    {
        SettleMonthDAL dal = new SettleMonthDAL(DbConnectionEnum.CaileBusiness);

        /// <summary>
        /// 查询对象集
        /// </summary>
        /// <param name="AccountID"></param>
        /// <param name="currentYear"></param>
        /// <returns></returns>
        public List<SettleMonthEntity> Querydivided(int AccountID, string currentYear)
        {
            return dal.Querydivided(AccountID, currentYear);
        }


        /// <summary>
        /// 结算查询
        /// </summary>
        /// <param name="UserName"></param>
        /// <returns></returns>
        public List<udv_SettleMonth> QueryCommission(string AccountName, string Month, int PageIndex, int PageSize, ref int RecordCount)
        {
            return dal.QueryCommission(AccountName, Month, PageIndex, PageSize, ref RecordCount);
        }

        public bool Insert(List<SettleMonthEntity> Entitys)
        {
            return dal.InsertSettleMonth(Entitys);
        }

        /// <summary>
        /// 更新对象
        /// </summary>
        /// <param name="Entity"></param>
        /// <returns></returns>
        public int ModifyEntity(SettleMonthEntity Entity)
        {
            return dal.ModifyEntity(Entity);
        }
        /// <summary>
        /// 查询用户对象
        /// </summary>
        /// <param name="AccountID"></param>
        /// <returns></returns>
        public SettleMonthEntity QueryEntity(int SettleMonthID)
        {
            return dal.QueryEntity(SettleMonthID);
        }

        /// <summary>
        /// 计算金额
        /// </summary>
        /// <param name="accountid"></param>
        /// <returns></returns>
        public int CalTotalAmount(int accountid)
        {
            int TotalAmount = 0;
            var paras = new DynamicParameters();
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" AccountID=@AccountID ");
            paras.Add("@AccountID", accountid);
            TotalAmount = dal.GetIntSingle(string.Format(" select SUM(SettleAmount) from [UN_SettleMonth] WHERE SettleStatus=3 and {0}", strSql), paras);
            return TotalAmount;
        }
    }
}
